<?php

namespace App\Controller\Index;


use App\Controller\BaseController;
use App\Request\Index\ClickHeartBeatRequest;
use Hyperf\Context\Context;
use App\Model\User;

class HeartBeatController extends BaseController
{

    /**
     * Note - 心跳判断, 每分钟记录用户最新点击时间
     * DateTime 2024/8/12 10:08
     * User Admin
     */
    public function clickHeartBeat(ClickHeartBeatRequest $request): \Psr\Http\Message\ResponseInterface
    {
        $uid = Context::get('user')['id'];
        $params = $this->request->post();
        $clickTime = $params['click_time'] ?? time();
        $request->execute($params);
        User::query()->where('id', $uid)->update(['click_time' => $clickTime]);
        return $this->return();
    }


}